import { _decorator, CCInteger, Node, tween, Vec2, Vec3 } from 'cc';
import { UICtrl } from '../../../Framework/Managers/UICtrl';
const { ccclass, property } = _decorator;

@ccclass('Door_Ctrl')
export class Door_Ctrl extends UICtrl {

    @property(CCInteger)
    type:number = 1;

    @property(Vec2)
    endPos:Vec2 = new Vec2(0,0);
    @property(Vec2)
    startPos:Vec2 = new Vec2(0,0);

    private verticalDoor:Node = null;
    private leftDoor:Node = null;
    private rightDoor:Node = null;
    private tewwnTime:number = 0.5;

    onLoad(){
        super.onLoad();
        if (this.type == 1) {
            this.verticalDoor = this.getChildOrComponent("VerticalDoor");
        }else{
            this.leftDoor = this.getChildOrComponent("LeftDoor");
            this.rightDoor = this.getChildOrComponent("RightDoor");
        }
    }

    closeDoor(){
        if (this.type == 1) {
            tween(this.verticalDoor).to(this.tewwnTime,{position:new Vec3(0,this.endPos.y,0)}).start();
        }else{
            tween(this.leftDoor).to(this.tewwnTime,{position:new Vec3(this.endPos.x,0,0)}).start();
            tween(this.rightDoor).to(this.tewwnTime,{position:new Vec3(this.endPos.y,0,0)}).start();
        }
    }

    openDoor(){
        if (this.type == 1) {
            tween(this.verticalDoor).to(this.tewwnTime,{position:new Vec3(0,this.startPos.y,0)}).start();
        }else{
            tween(this.leftDoor).to(this.tewwnTime,{position:new Vec3(this.startPos.x,0,0)}).start();
            tween(this.rightDoor).to(this.tewwnTime,{position:new Vec3(this.startPos.y,0,0)}).start();
        }
    }

}


